package small.common.designPattern.structure.proxy;

/**
 * @Author zhoujin
 * @Date 2022/6/26 16:19
 */
public class  TargetSource<T> {

    private Object target;

    private final Class<T> targetClass;

    private final Class<?>[] interfaces;

    public TargetSource(Object target) {
        if (target == null){
            throw new IllegalArgumentException("Target must not be null");
        }
        this.target = target;
        this.targetClass = (Class<T>) target.getClass();
        this.interfaces = this.targetClass.getInterfaces();
    }

    public TargetSource(Class<?> targetClass) {
        if (targetClass == null){
            throw new IllegalArgumentException("TargetClass must not be null");
        }
        this.targetClass = (Class<T>) targetClass;
        if (targetClass.isInterface()){
            interfaces = new Class[]{targetClass};
        }else {
            this.interfaces = this.targetClass.getInterfaces();
        }

    }

    /**
     * 获取目标对象
     * @return
     */
    public Object getTarget() {
        return target;
    }

    /**
     * 获取目标类
     * @return
     */
    public Class<T> getTargetClass() {
        return targetClass;
    }

    /**
     * 获取所有接口类
     * @return
     */
    public Class<?>[] getInterfaces() {
        return interfaces;
    }
}
